/**
 * @author liangxi
 * @since 2023/12/21
 */
#ifndef DESIGNPATTERN_SINGLETON2_H
#define DESIGNPATTERN_SINGLETON2_H

namespace Singleton {

    /**
     * 此例子采取饿汉式创建实例
     * 在程序运行的时候就创建一份实例，保证程序在多线程下可以正确运行
     */
    class Singleton2 {
    public:
        static Singleton2 *getInstance() {
            return instance;
        }

    private:
        Singleton2() = default;

        Singleton2(const Singleton2 &rhs) = default;


        //   static Singleton2* instance = new Singleton2(); error
        static Singleton2 *instance;

    };

    Singleton2 *Singleton2::instance = new Singleton2();

} // Singleton

#endif //DESIGNPATTERN_SINGLETON2_H
